,

( ,

)

g

(a cross). Therefore two entries (7 and 3) were popped up from

to take part in an operation. The summed value, which was ten,

ed back to the stack. At this time, the stack was composed of only

e and all the tokens in an RPN string have been scanned. The

alue in the stack (ten) was the final computation result.

Fig. 8.6. The stack use for parsing an RPN string for the evaluation.

R code shown below was used for this simple example,

3y*+xz*+'

=c(1,2,3)

values)=c('x','y','z')

ors=c('*','+')

LL

in 1:nchar(rpn))

n=substr(rpn,i,i)

ength(which(operators==token))>0)

ps=stk[length(stk):(length(stk)-1)]

k=stk[-(length(stk):(length(stk)-1))]

(token=='*') stk=c(stk,prod(pops))

(token=='+') stk=c(stk,sum(pops))

se {

riable=which(names(values)==token)

(length(variable)>0)

{

stk=c(stk,values[variable])

else {

stk=c(stk,as.numeric(token))

}